#include "wuSolidRectangle.h"

wuSolidRectangle::wuSolidRectangle()
{

}

wuSolidRectangle::~wuSolidRectangle()
{
}


void wuSolidRectangle::set2d(ofxBox2d * _box2d, ofRectangle rect)
{
	wuBase2d::setup(_box2d, rect);

	// base rectangle
	base.setPhysics(1, 0.5, 0.5);
	base.setup(box2d->getWorld(), rect.x+rect.width/2, rect.y+rect.height/2, rect.width/2, rect.height/2);

}

void wuSolidRectangle::setup(ofxBox2d * _box2d, ofImage *_skin, ofRectangle rect)
{
	wuBaseSkin::setSkin(_skin, rect);
	set2d(_box2d, rect);
}

void wuSolidRectangle::setup(ofxBox2d * _box2d, ofRectangle rect)
{
	set2d(_box2d, rect);
}

void wuSolidRectangle::draw(bool bDrawlines, int offX)
{
	wuBaseSkin::draw(offX);

	if(bDrawlines && offX==0)
         base.draw();
}

void wuSolidRectangle::update()
{
	// l' skin es mou amb la base
	posSkin = base.getPosition();
	angSkin = ofDegToRad(base.getRotation());

}

void wuSolidRectangle::clear()
{
    base.destroy();
}

void wuSolidRectangle::setPosition(int _x,int _y)
{
	base.setPosition(_x,_y);
}
void wuSolidRectangle::setPosition(ofPoint _pos)
{
	base.setPosition(_pos);
}

void wuSolidRectangle::touch(int _x,int _y, int forceX, int forceY)
{
/*		ofPoint pos;

        pos = base.getPosition();

		if( (_x > pos.x-pos.w) && (_x < pos.x+w) && (_y > pos.y-h) && (_y < pos.y+h) )
		{
			if(forceX>0)
			{
				if( (_x > pos.x-w) && (_x < pos.x))
					base.addImpulseForce(ofPoint(pos.x-w,pos.y), ofPoint(forceX,0));
				if( (_x > pos.x) && (_x < pos.x+w))
					base.addImpulseForce(ofPoint(pos.x+w,pos.y), ofPoint(0-forceX,0));
			}
			if(forceY>0)
			{
				if( (_y > pos.y-h) && (_y < pos.y) )
					base.addImpulseForce(ofPoint(pos.x,pos.y-h), ofPoint(0,0-forceY));
				if( (_y > pos.y) && (_y < pos.y+h) )
					base.addImpulseForce(ofPoint(pos.x,pos.y+h), ofPoint(0,forceY));
			}
		}
*/
}

bool wuSolidRectangle::drag(int _x,int _y)
{
        bool bDrag=false;
		ofPoint pos;

        pos = base.getPosition();

		if( (_x > pos.x-base.getWidth()) && (_x < pos.x+base.getWidth()) && (_y > pos.y-base.getHeight()) && (_y < pos.y+base.getHeight()) )
		{
		    base.setPosition(_x,_y);
            bDrag=true;
		}
	    return bDrag;
}

void wuSolidRectangle::stop_gravity()
{
	base.setVelocity(0,0);
}

